package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.TSCServiceType;
import com.shrcl.engineerprocess.domain.TSCServiceTypeDefinition;
import com.shrcl.engineerprocess.domain.TSCServiceTypeInstance;
import com.shrcl.engineerprocess.domain.TSCServiceTypeOptionItem;
import com.shrcl.engineerprocess.domain.impl.TSCServiceTypeDefinitionImpl;
import com.shrcl.engineerprocess.domain.impl.TSCServiceTypeImpl;
import com.shrcl.engineerprocess.domain.impl.TSCServiceTypeOptionItemImpl;
import com.shrcl.engineerprocess.domain.proxy.TSCServiceTypeInstanceProxy;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("TSCSERVICETYPEINSTANCE_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "tscservicetypeinstance")
public class TSCServiceTypeInstanceImpl extends BaseModelObject implements TSCServiceTypeInstance {
  public TSCServiceTypeInstanceImpl() {
    super();
  }
  
  public TSCServiceTypeInstanceImpl(final TSCServiceTypeDefinition typeDefinition) {
    super();
    this.typeDefinition = typeDefinition;
  }
  
  @JoinColumn(name = "typeDefinition_id")
  @ManyToOne(targetEntity = TSCServiceTypeDefinitionImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private TSCServiceTypeDefinition typeDefinition;
  
  public TSCServiceTypeDefinition getTypeDefinition() {
    return this.typeDefinition;
  }
  
  public TSCServiceTypeInstance setTypeDefinition(final TSCServiceTypeDefinition typeDefinition) {
    this.typeDefinition = typeDefinition;
    return this;			
    
  }
  
  @JoinColumn(name = "serviceType_id")
  @ManyToOne(targetEntity = TSCServiceTypeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private TSCServiceType serviceType;
  
  public TSCServiceType getServiceType() {
    return this.serviceType;
  }
  
  public TSCServiceTypeInstance setServiceType(final TSCServiceType serviceType) {
    this.serviceType = serviceType;
    return this;			
    
  }
  
  @JoinColumn(name = "selected_id")
  @ManyToOne(targetEntity = TSCServiceTypeOptionItemImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private TSCServiceTypeOptionItem selected;
  
  public TSCServiceTypeOptionItem getSelected() {
    return this.selected;
  }
  
  public TSCServiceTypeInstance setSelected(final TSCServiceTypeOptionItem selected) {
    this.selected = selected;
    return this;			
    
  }
  
  public String getEntityName() {
    String _name = this.serviceType.getName();
    return _name;
  }
  
  public static TSCServiceTypeInstance create(final TSCServiceTypeDefinition typeDefinition, final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.TSCServiceTypeInstance tSCServiceTypeInstance = new com.shrcl.engineerprocess.domain.impl.TSCServiceTypeInstanceImpl(
    	typeDefinition
    );
    objectFactory.create(tSCServiceTypeInstance);
    return tSCServiceTypeInstance;			
    
  }
  
  public static TSCServiceTypeInstance createTSCServiceTypeInstanceImpl(final TSCServiceTypeDefinition typeDefinition, final IObjectFactory objectFactory, final Procedure1<TSCServiceTypeInstance> init) {
    com.shrcl.engineerprocess.domain.TSCServiceTypeInstance tSCServiceTypeInstance = new com.shrcl.engineerprocess.domain.impl.TSCServiceTypeInstanceImpl(
    	typeDefinition
    );
    objectFactory.create(tSCServiceTypeInstance);
    init.apply(tSCServiceTypeInstance);
    
    return tSCServiceTypeInstance;			
    
  }
  
  public TSCServiceTypeInstanceProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.TSCServiceTypeInstanceProxy proxy = new com.shrcl.engineerprocess.domain.proxy.TSCServiceTypeInstanceProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
